/**
 * Created by 尼恩 at 疯狂创客圈
 */

package com.crazymakercircle.imClient.protoConverter;

import com.crazymakercircle.im.common.bean.User;
import com.crazymakercircle.im.common.bean.msg.ProtoMsg;
import com.crazymakercircle.imClient.session.ClientSession;


/**
 * 登陆消息 Converter
 *
 * 1、调用构造方法 传入基础的数据 User session
 *   传入基础的字段  type 消息类型
 *                seqId
 *                session --> 设置sessionId
 *
 * 2、调用build无参方法
 *    先获取基础数据  ProtoMsg.Message.Builder outerBuilder = getOuterBuilder(-1);
 *    构造登陆消息 数据
 *
 *
 */
public class LoginMsgConverter extends BaseConverter {
    private final User user;

    public LoginMsgConverter(User user, ClientSession session) {
        super(ProtoMsg.HeadType.LOGIN_REQUEST, session);
        this.user = user;
    }

    public ProtoMsg.Message build() {

        // 先获取基础数据
        ProtoMsg.Message.Builder outerBuilder = getOuterBuilder(-1);

        // 构造登陆消息 数据
        ProtoMsg.LoginRequest.Builder lb =
            ProtoMsg.LoginRequest.newBuilder()
                    .setDeviceId(user.getDevId())
                    .setPlatform(user.getPlatform().ordinal())
                    .setToken(user.getToken())
                    .setUid(user.getUid());

        ProtoMsg.Message requestMsg = outerBuilder.setLoginRequest(lb).build();

        return requestMsg;
    }


    public static ProtoMsg.Message build(  User user, ClientSession session) {
        LoginMsgConverter converter =  new LoginMsgConverter(user, session);
        return converter.build();

    }


}


